package cn.tedu.test;

import java.util.Scanner;

public class CountPrimeNumber {
    public static void main(String[] args) {
        System.out.println("请输入数组n,求n以内的质数数量");
        int n=new Scanner(System.in).nextInt();
        count(n);
    }

    private static void count(int n) {
        if(n<2){
            System.out.println("没有质数");
            return;
        }
        if(n==2){
            System.out.println("有一个质数");
            return;
        }

        int count=1;
        outer:
        for(int i=3;i<=n;i++){
            double max=1+Math.sqrt(i);
            for(int j=2;j<=max;j++){
                if(i%j==0){
                    continue outer;
            }

            }
            count++;
        }
        System.out.println(n+"以内有"+count+"个质数");
    }
}
